home *** CD-ROM | disk | FTP | other *** search
/ Your Choice 3 / Your Choice Software Collection 3.iso / prgmming / flames / flames.pas < prev    next >
Pascal/Delphi Source File  |  1993-08-27  |  3KB  |  126 lines

  1. program flames;
  2. {**************************************************************************}
  3. {*                                                                        *}
  4. {*    FLAMES by M.D.Mackey  (C) 1993                                      *}
  5. {*        This code released into the public domain. It may be freely     *}
  6. {*        used, distributed and modified. I would appreciate it if        *}
  7. {*        credit were given, however. If you have any improvements,       *}
  8. {*        find any bugs etc. mail me at mackey@aqueous.ml.csiro.au        *}
  9. {*        with MARK: in the subject header.                               *}
  10. {*                                                                        *}
  11. {**************************************************************************}
  12.  
  13.  
  14. uses crt;
  15. type bigarr=array[0..102,0..159] of integer;
  16. var f:bigarr;
  17.     i,j,k,l:word;
  18.     delta:integer;
  19.     pal:array[0..255,1..3] of byte;
  20.     ch:char;
  21.  
  22. procedure setmode13;
  23. assembler;
  24. asm
  25.   mov ax,13h
  26.   int 10h
  27. end;
  28.  
  29. procedure setpalette;
  30. var mapfile:text;
  31.     i,j:integer;
  32.  
  33. begin
  34.   assign(mapfile,'flames5.map');  {kludgy, but it works!}
  35.   reset(mapfile);
  36.   for i:=0 to 255 do
  37.   for j:=1 to 3 do
  38.   begin
  39.     read(mapfile,pal[i,j]);
  40.     pal[i,j]:=pal[i,j] shr 2;
  41.   end;
  42.   asm
  43.     mov si,offset pal
  44.     mov cx,768      {no of colour registers}
  45.     mov dx,03c8h
  46.     xor al,al      {First colour to change pal for = 0}
  47.     out dx,al
  48.     inc dx
  49. @1: outsb
  50.     dec cx        {safer than rep outsb}
  51.     jnz @1
  52.   end;
  53. end;
  54.  
  55. begin
  56.   setmode13;
  57.   setpalette;
  58.   randomize;
  59.   ch:=' ';
  60.   for i:=0 to 102 do
  61.   for j:=0 to 159 do
  62.     f[i,j]:=0;        {initialise array}
  63.  
  64.   repeat
  65.     asm                {move lines up, averaging}
  66.       mov cx,16159;    {no. elements to change}
  67.       mov di,offset f
  68.       add di,320   {di points to 1st element of f in upper row (320 bytes/row)}
  69. @1:
  70.       mov ax,ds:[di-2]
  71.       add ax,ds:[di]
  72.       add ax,ds:[di+2]
  73.       add ax,ds:[di+320]
  74.       shr ax,2     {divide by 4: average 4 elements of f}
  75.       jz @2
  76.       sub ax,1
  77. @2:   mov word ptr ds:[di-320],ax
  78.       add di,2
  79.       dec cx
  80.       jnz @1    {faster than _loop_ on 486}
  81.     end;
  82.  
  83.  
  84.     for j:=0 to 159 do  {set new bottom line}
  85.     begin
  86.       if random<0.4 then
  87.         delta:=random(2)*255;
  88.       f[101,j]:=delta;
  89.       f[102,j]:=delta;
  90.     end;
  91.  
  92.  
  93.     asm                 {output to screen}
  94.       mov si,offset f
  95.       mov ax,0a000h
  96.       mov es,ax
  97.       mov di,0
  98.       mov dx,100
  99. @3:
  100.       mov bx,2
  101. @2:
  102.       mov cx,160
  103. @1:
  104.       mov al,[si]
  105.       mov ah,al
  106.       mov es:[di],ax     {word aligned write to display mem}
  107.       add di,2
  108.       add si,2
  109.       dec cx
  110.       jnz @1
  111.  
  112.       sub si,320
  113.       dec bx
  114.       jnz @2
  115.  
  116.       add si,320
  117.       dec dx
  118.       jnz @3
  119.     end;
  120.     if keypressed then ch:=readkey;
  121.   until ch=#27;
  122.   asm   {restore text mode}
  123.     mov ax,03h
  124.     int 10h
  125.   end;
  126. end.